using System;
using System.Collections.Generic;
using System.Text;
using Crm.Domain;
using Util;

namespace Ordering.Domain
{
    /// <summary>
    /// An ENTITY that is the root of an AGGREGATE that represents a record of a request by a buyer for some goods.
    /// </summary>
    public partial class Order
    {
        #region Fields

        private Customer _customer;
        private OrderState _state;

        #endregion

        #region Constructor

        public Order(Customer customer)
        {
            # region Preconditions

            ArgumentValidation.ThrowIfNull(customer, "customer");

            # endregion

            _customer = customer;
            _state = new NewOrderState(this);
        }

        #endregion

        #region Properties

        /// <summary>
        /// Gets a value that indicates what state the order is in.
        /// </summary>
        public OrderStateKind State
        {
            get { return _state.Kind; }
        }

        /// <summary>
        /// Gets or sets the state that the order is in.
        /// </summary>
        public OrderState CurrentState
        {
            get { return _state; }
            private set
            {
                _state = value;
            }
        }

        public Customer Customer
        {
            get { return _customer; }
        }

        #endregion

        public OrderLine CreateOrderLine()
        {
            throw new Exception("The method or operation is not implemented.");
        }

        /// <summary>
        /// Moves this order to the <see cref="OrderStateKind.Processing"/> state.
        /// </summary>
        public void Processing()
        {
            _state.Processing();
        }
    }
}
